package com.dadi.vine.user.controller;

import java.util.Map;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.dadi.vine.user.dto.UserDto;
import com.dadi.vine.user.service.SysService;
import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 类说明
 *
 * @Author ChenYL
 * @Email chenyl@dadi18.com
 * @Date 2017年10月31日 下午4:12:01
 */
@CrossOrigin(maxAge = 3600)
@Api(value = "用户接口", description = "用户接口测试类")
@RestController
@RequestMapping("/sys")
public class SysController {

	@Autowired
	SysService sysService;
	// @Autowired
	// JedisClient jedisClient;

	@ApiOperation(value = "查询用户列表")
	@RequestMapping(value = "/getUser", method = RequestMethod.GET)
	public Map<String, Object> getUser() throws Exception {
		System.out.println("进入SysController");
		return sysService.getUser();
	}

	@ApiOperation(value = "根据用户编号获取用户详细信息")
	@RequestMapping(value = "/getUserByUserId", method = RequestMethod.GET)
	public Map<String, Object> getUserByUserId(String userId) throws Exception {
		System.out.println("进入SysController,参数为=" + userId);
		Map<String, Object> map = sysService.getUserByUserId(userId);
		System.out.println(new Gson().toJson(map));
		return map;
	}

	@ApiOperation(value = "获取用户详细信息")
	@RequestMapping(value = "/getUserByUserId", method = RequestMethod.POST)
	public Map<String, Object> getUserByUserId(@Valid @RequestBody UserDto dto, BindingResult result) throws Exception {
		System.out.println("进入SysController,参数为=" + new Gson().toJson(dto));
		Map<String, Object> map = sysService.getUserByUserId(dto.getUserId());
		System.out.println(new Gson().toJson(map));
		return map;
	}
}